package com.siwei.mes.service.system.impl;

import com.siwei.mes.entity.system.TestProjectSpecConfig;
import com.siwei.mes.mapper.system.TestProjectSpecConfigMapper;
import com.siwei.mes.service.system.TestProjectSpecConfigService;
import org.springframework.stereotype.Service;
import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;

import javax.annotation.Resource;
import java.util.List;

/**
 * 试验项目材料规格判定配置(TestProjectSpecConfig)表服务实现类
 *
 * @author makejava
 * @since 2024-08-26 22:15:48
 */
@Service
public class TestProjectSpecConfigServiceImpl implements TestProjectSpecConfigService {
    @Resource
    private TestProjectSpecConfigMapper testProjectSpecConfigMapper;
    
    @Override
    public Long create(TestProjectSpecConfig entity) {
        testProjectSpecConfigMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int batchCreate(List<TestProjectSpecConfig> entityList) {
        return testProjectSpecConfigMapper.insertList(entityList);
    }

    @Override
    public void update(TestProjectSpecConfig entity) {
        TestProjectSpecConfig testProjectSpecConfig = testProjectSpecConfigMapper.selectByPrimaryKey(entity.getId());
        assertTrue(testProjectSpecConfig == null, "试验项目材料规格判定配置信息不存在");
        testProjectSpecConfigMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        TestProjectSpecConfig testProjectSpecConfig = testProjectSpecConfigMapper.selectByPrimaryKey(id);
        assertTrue(testProjectSpecConfig == null, "试验项目材料规格判定配置信息不存在");
        testProjectSpecConfigMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<TestProjectSpecConfig> getPage(PageQuery<TestProjectSpecConfig, TestProjectSpecConfig> query) {
        TestProjectSpecConfig searchParam = query.getParams();  
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> testProjectSpecConfigMapper.getList(searchParam));
    }

    @Override
    public TestProjectSpecConfig loadById(Long id) {
        return testProjectSpecConfigMapper.loadById(id);
    }

    @Override
    public List<TestProjectSpecConfig> getAll(TestProjectSpecConfig entity) {
        return testProjectSpecConfigMapper.getList(entity);
    }
}
